package cn.shadowsouls.admin.controller;

import cn.shadowsouls.common.domain.AjaxResult;
import cn.shadowsouls.common.domain.Result;
import cn.shadowsouls.system.bean.*;
import cn.shadowsouls.system.manger.UserManger;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户操作接口
 *
 * @author shadowsouls
 * @version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/")
public class UserController {


    @Autowired
    UserManger userManger;

    // 可以获取post过来的信息以及token
    @ApiOperation(value = "登录接口")
    @PostMapping("login")
    String login(@ApiParam(value = "登录数据", required = true) @RequestBody LoginData data) {

        return String.valueOf(userManger.getAuthorCode(data));

    }


    @ApiOperation(value = "注册接口")
    @PostMapping("register")
    String register(@ApiParam(value = "注册数据") @RequestBody RegisterData registerData) {

        if (userManger.register(registerData))
            return "注册成功";
        return "注册失败";
    }

    @ApiOperation(value = "登出接口")
    @GetMapping("logout")
    Result logout(@ApiParam(value = "授权码") @RequestHeader String authorization) {

        userManger.logout(authorization);

        return null;

    }

}
